<div class="content-wrapper">
    <!-- 内容标题 -->
    <section class="content-header">
        <h1>
            <small>品牌故事列表</small>/编辑版块
        </h1>
        <ol class="breadcrumb display-none">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">生成</a></li>
            <li class="active">添加</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content pd-top0">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body solist">
                        <div class="detail-page-sy">
                            <form class="form-horizontal" action="<?=base_url()?>index.php/admin/brandinfo/update/<?= $id?>" method="post" id='EditForm'>
                                <div class="detail-page-border">
                                    <div class="detail_con">
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">标题：</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="请输入板块标题。"
                                                  name="brandinfo[name]" fld='name' value="<?php echo (isset($name)?$name:'') ?>">
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
										<div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">标签：</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="请输入标签名。"
                                                  name="brandinfo[tagname]" fld='tagname' value="<?php echo (isset($tagname)?$tagname:'') ?>">
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
                                        <?php if('yes' == $is_admin){?>
                                            <div class="form-group hd_title">
                                                <label class="col-sm-2 control-label">品牌：</label>
                                                <div class="col-sm-4">
                                                    <select name="brandinfo[brand_id]" fld='brand_id' style='width:150px;' class='form-control'>
                                                        <option value="">请选择</option>
                                                        <?php
                                                        foreach ($brand_opts as $key => $opts) {
                                                        ?>
                                                            <option value="<?=$opts['id'] ?>" <?php if(isset($brand_id) && $brand_id == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                                                        <?php
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                                <div style='color:red;'></div>
                                            </div>
                                        <?php }?>
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">内容：</label>
                                            <div class="col-sm-8">
                                                <pre style="height: 700px;border: none;" id="editor"></pre>
												<input type="hidden" name="brandinfo[content]" fld='content'>
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
                                    </div>
                                    <div class="box-footer align-center">

                                        <button type="button" class="btn btn-primary btn-big bg-pink" onClick="getEditorVlaue()">提交</button>
                                        <a href="<?=base_url()?>index.php/admin/brandinfo/index" class="btn btn-default btn-big">取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!--/.col (left) -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>


<script src="<?= base_url()?>/style/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="<?= base_url()?>/style/bootstrap/js/bootstrap.min.js"></script>
<script src="<?= base_url()?>/style/dist/js/app.min.js"></script>
<!-- <script src="../dist/js/demo.js"></script> -->

<script src="<?= base_url()?>/style/js/base/ace/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
	//$(function(){


		var editor = ace.edit("editor");
		editor.setTheme("ace/theme/twilight");
		editor.session.setMode("ace/mode/html");
		function aceInit(data){console.log(data);
			editor.setValue(data)
		}
        $.post('<?=base_url()?>index.php/admin/brandinfo/postCodeContent/<?= $id?>',{'ajax':1},function(rest){
            if(rest == '') return false;
            aceInit(rest);
        });
		// if($('#brand_content').html() != ''){
		// 	aceInit($('#brand_content').html());
		// }
	//});
    // $.get("/getdata/gethtml",function(data){
    //   aceInit(data.data)
    // },"json")


</script>

<script type="text/javascript">
    // var pageMenu = {"active": [1]};
    var is_submit = 1;
    function getEditorVlaue(){
        // console.log(editor.getValue());
        var idx = 1;
        $('#EditForm input[fld=name]').val($.trim($('#EditForm input[fld=name]').val()));
        if($('#EditForm input[fld=name]').val() == ''){
            $('#EditForm input[fld=name]').parent().next().html('请输入板块标题。');
            idx = 0;
        }else{
            $('#EditForm input[fld=name]').parent().next().html('');
        }
        if($('#EditForm input[fld=brand_id]').length > 0){
            if($('#EditForm input[fld=brand_id]').val() == ''){
                $('#EditForm input[fld=brand_id]').parent().next().html('请选择品牌。');
            }else{
                $('#EditForm input[fld=brand_id]').parent().next().html('');
            }
        }
        var content = editor.getValue();
        content = $.trim(content);
        if(content == ''){
            $('#editor').parent().next().html('请输入内容。');
            idx = 0;
        }else{
            $('#editor').parent().next().html('');
        }
        if(0 == idx){
            return false;
        }
        $('#EditForm input[fld=content]').val(content);
        if(1 != is_submit){
            return false;
        }
        is_submit = 2;
        $('#EditForm').submit();
    }
    var error_code = "<?= (isset($error_code)?$error_code:'')?>";
    if(error_code != ''){
        $('#EditForm input[fld=name]').parent().next().html(error_code);
    }
</script>
<script src="<?= base_url()?>/style/js/vendors.js" type="text/javascript"></script>
